package cn.xiong.request_hystrix.aop;

import cn.xiong.request_hystrix.annotation.MappingAndCircuit;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.support.StaticMethodMatcherPointcut;
import org.springframework.core.annotation.AnnotatedElementUtils;

import java.lang.reflect.Method;

/**
 * @auther 10349 XIONGSY
 * @create 2021/8/20
 */
public class CircuitBreakerPointcut extends StaticMethodMatcherPointcut {
    @Override
    public boolean matches(Method method, Class<?> targetClass) {
        //找到原始方法对象
        Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
        if (AnnotatedElementUtils.hasAnnotation(targetClass, MappingAndCircuit.class)
                || AnnotatedElementUtils.hasAnnotation(specificMethod, MappingAndCircuit.class)) {
            return true;
        }
        return false;
    }
}
